package com.atguigu.gulimall.common.exception;

import lombok.Data;

/**
 * @author: xuesm
 * @date: 2024/12/17 16:32
 */
@Data
public class BizException extends RuntimeException{

    private static final long serialVersionUID = -7864604160297181941L;

    protected final ErrorCode errorCode;

    /**
     * 无参默认构造 UNKNOWN_EXCEPTION
     */
    public BizException() {
        super(BigCodeEnum.UNKNOWN_EXCEPTION.getMsg());
        this.errorCode = BigCodeEnum.UNKNOWN_EXCEPTION;
    }

    /**
     * 指定错误码构造通用异常
     * @param errorCode 错误码
     */
    public BizException(final ErrorCode errorCode) {
        super(errorCode.getMsg());
        this.errorCode = errorCode;
    }

    /**
     * 指定详细描述构造通用异常
     * @param message 详细描述
     */
    public BizException(final String message) {
        super(message);
        this.errorCode = BigCodeEnum.UNKNOWN_EXCEPTION;
    }

    /**
     * 指定导火索构造通用异常
     * @param t 导火索
     */
    public BizException(final Throwable t) {
        super(t);
        this.errorCode = BigCodeEnum.UNKNOWN_EXCEPTION;
    }

    /**
     * 构造通用异常
     * @param errorCode 错误码
     * @param message 详细描述
     */
    public BizException(final ErrorCode errorCode, final String message) {
        super(message);
        this.errorCode = errorCode;
    }

    /**
     * 构造通用异常
     * @param errorCode 错误码
     * @param t 导火索
     */
    public BizException(final ErrorCode errorCode, final Throwable t) {
        super(errorCode.getMsg(), t);
        this.errorCode = errorCode;
    }

    /**
     * 构造通用异常
     * @param detailedMessage 详细描述
     * @param t 导火索
     */
    public BizException(final String detailedMessage, final Throwable t) {
        super(detailedMessage, t);
        this.errorCode = BigCodeEnum.UNKNOWN_EXCEPTION;
    }

    /**
     * 构造通用异常
     * @param errorCode 错误码
     * @param detailedMessage 详细描述
     * @param t 导火索
     */
    public BizException(final ErrorCode errorCode, final String detailedMessage,
                        final Throwable t) {
        super(detailedMessage, t);
        this.errorCode = errorCode;
    }

    public ErrorCode getErrorCode() {
        return errorCode;
    }
}
